layui.use(['form', 'jquery', 'layer', 'table', 'laydate', 'laypage', 'upload', 'element'], function() {
	var form = layui.form;
	var layer = layui.layer;
	var $ = layui.$;

	var send_info = function(string_uri, json_data, fun_callback) {
		layer.load(2);
		$.ajax({
			type: "post",
			url: string_uri,
			async: true,
			data: json_data,
			dataType: 'json',
			success: function(data) {
				layer.closeAll('loading');
				if (data['code'] == -101) {
					location.href = 'login.html';
					return false;
				} else if (data['code'] == -200) {
					layer.msg(data['msg'], {
						icon: 2,
						anim: 6
					});
					return false;
				} else if (data['code'] == 0 && data['msg'] == '参数错误') {
					layer.msg('参数错误', {
						icon: 2,
						anim: 6
					});
				} else {
					return fun_callback(data);
				}
			},
			error: function(xhr, type, errorThrown) {
				layer.msg('请求失败，访问地址：' + string_uri, {
					icon: 2,
					anim: 6
				});
				layer.closeAll('loading');
			}
		});
	};
	
	// 关闭页面
	$('#close_page').on('click', function() {
		parent.layer.closeAll('iframe');
	})

	$('.img-out').on('mouseover', function() {
		$(this).find('.btns').show();
	}).on('mouseleave', function() {
		$(this).find('.btns').hide();
	})
	$('.btns').on('click', function() {
		var id = $(this).attr('data-id');
		var othis = $(this);
		layer.confirm('确定删除吗？', function(index) {
			send_info(delete_img_url, {
				id: id
			}, function() {
				layer.closeAll();
				othis.parent().remove();
				layer.mg('删除成功', {
					icon: 1,
					anim: 6
				})
			})
		})
	})

})